package com.zy.pro.utils;

import java.math.BigDecimal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.zy.utils.VerifyIdCard;

public class ValidFactory {
	//业主用户导入验证（个别验证公共）
	private static Pattern validMobilePhone = Pattern.compile("^13[0-9]{9}$|14[0-9]{9}|15[0-9]{9}$|18[0-9]{9}$");
	private static Pattern validRealName = Pattern.compile("^[\\u4E00-\\u9FA5\\uf900-\\ufa2d\\w\\.\\s]{2,15}$");
	private static Pattern validEmail = Pattern.compile("^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
	
	//此身份证正则验证有bug
//	private static Pattern validIdCard = Pattern.compile("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{4}$");
	
	private static Pattern validFloorSpace = Pattern.compile("^\\d+(\\.\\d+)?$");
	private static Pattern validCarport = Pattern.compile("^[\u4E00-\u9FA5\uf900-\ufa2d\\w\\.\\s]{2,12}$");
	private static Pattern validIdNum = Pattern.compile("^[\u4E00-\u9FA5\uf900-\ufa2d\\w\\.\\s]{2,12}$");
	private static Pattern validGender = Pattern.compile("^[男|女]$");
	private static Pattern validYesOrNo = Pattern.compile("^[是|否]$");
	
	
	//缴费导入验证（个别验证公共）
	private static Pattern validCostCycle = Pattern.compile("^\\d{1,2}$");
//	private static Pattern validStartTime = Pattern.compile("");
	private static Pattern validCost = Pattern.compile("^\\d{1,4}(\\.\\d{1,2})?$");
	private static Pattern validRemark = Pattern.compile("^[\\u4E00-\\u9FA5\\uf900-\\ufa2d\\w\\.]{0,280}$");
	
	
	//商家导入（个别验证公共）
	private static Pattern validShopName = Pattern.compile("^[\\u4E00-\\u9FA5\\uf900-\\ufa2d\\w\\.]{2,25}$");
	private static Pattern validCategoryList = Pattern.compile("^[银行|超市|邮政|餐饮店|洗衣房|美容美发店|药店|文化用品店|维修点|社区活动中心|菜市场|卫生所]$");
	private static Pattern validLng = Pattern.compile("^[\\w\\W]{8,25}$");
	private static Pattern validLat = Pattern.compile("^[\\w\\W]{8,25}$");
	private static Pattern validCity = Pattern.compile("^[\\u4E00-\\u9FA5\\uf900-\\ufa2d]{2,5}$");
	
	
	//3天配送订单详情导入
	private static Pattern validDistributionId = Pattern.compile("^(\\d{1,20}-)([\\u4E00-\\u9FA5\\uf900-\\ufa2d\\w\\.]{1,10})$");
	private static Pattern validSendTime = Pattern.compile("[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}[ ]{1}[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$");
	
	//员工导入
	private static Pattern validPassword = Pattern.compile("^[a-zA-Z0-9]{6,15}$");
	
	public static boolean validDistributionId(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validDistributionId.matcher(str.trim());
		return m.find();
	}
	public static boolean validSendTime(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validSendTime.matcher(str.trim());
		return m.find();
	}
	
	
	public static boolean validShopName(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validShopName.matcher(str.trim());
		return m.find();
	}
	public static boolean validCategoryList(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validCategoryList.matcher(str.trim());
		return m.find();
	}
	public static boolean validLng(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validLng.matcher(str.trim());
		return m.find();
	}
	public static boolean validLat(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validLat.matcher(str.trim());
		return m.find();
	}
	public static boolean validCity(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validCity.matcher(str.trim());
		return m.find();
	}
	
	public static boolean validCostCycle(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validCostCycle.matcher(str.trim());
		return m.find();
	}
	public static boolean validCost(Object obj){
		if(obj == null){
			return true;
		}
		if(obj instanceof BigDecimal || obj instanceof Double){
			return true;
		}
		return false;
	}
	public static boolean validRemark(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validRemark.matcher(str.trim());
		return m.find();
	}
	
	public static boolean validFloorSpace(Object obj){
		if(obj == null){
			return true;
		}
		Matcher m = validFloorSpace.matcher(obj.toString().trim());
		return m.find();
	}
	public static boolean validCarport(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validCarport.matcher(str.trim());
		return m.find();
	}
	public static boolean validIdNum(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validIdNum.matcher(str.trim());
		return m.find();
	}
	public static boolean validGender(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validGender.matcher(str.trim());
		return m.find();
	}
	public static boolean validYesOrNo(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validYesOrNo.matcher(str.trim());
		return m.find();
	}
	
	public static boolean validMobilePhone(Object obj){
		if(obj == null){
			return true;
		}
		Matcher m = validMobilePhone.matcher(obj.toString().trim());
		return m.find();
	}
	
	public static boolean validEmail(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validEmail.matcher(str.trim());
		return m.find();
	}
	
	public static boolean validRealName(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validRealName.matcher(str.trim());
		return m.find();
	}
	
	public static boolean validIdCard(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
//		Matcher m = validIdCard.matcher(str.trim());
//		return m.find();
		return VerifyIdCard.verify(str.trim());
				
	}
	
	public static boolean validPassword(String str){
		if(str == null || "".equals(str.trim())){
			return true;
		}
		Matcher m = validPassword.matcher(str.trim());
		return m.find();
	}
	
	public static void main(String[] args) {
		System.out.println(ValidFactory.validPassword("123456a"));
	}
}
